<template>
  <div class="login">
    <div class="login_box">
      <div class="avatar_box">
        <img src="@/assets/images/lbg.jpg" alt="" />
      </div>
      <el-form class="login_form" :model="userData">
        <el-form-item label-width="0px">
          <el-input
            prefix-icon="el-icon-user"
            placeholder="请输入账号"
            v-model="userData.uid"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-input
            prefix-icon="el-icon-lock"
            type="password"
            placeholder="请输入密码"
            v-model="userData.pwd"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="loginbtn" @click="loginFun"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { setCookie } from "@utils/cookie.js";
import { loginFun } from "@network/api/login.js";
export default {
  name: "Login",
  data() {
    return {
      userData: {
        uid: "",
        pwd: "",
      },
    };
  },
  methods: {
    async loginFun() {
      let res = await loginFun(this.userData);
      console.log("登录", res);

      if (res.data.code&&res.data.code==200) {
        this.$message({
          message: "登录成功！",
          type: "success",
        });
        setCookie("_token", res.data.data.token);
        this.$router.push({
          path: "/",
        });
      } else {
        this.$message({
          message: "用户名或密码错误！",
          type: "error",
        });
      }
    },
  },
};
</script>

<style>
.login {
  height: 100vh;
  width: 100vw;
  background-image: url("@/assets/images/loginbg.jpg");
  background-size: cover;
}
.login_box {
  width: 400px;
  height: 280px;
  background-color: #fff;
  position: absolute;
  border-radius: 10px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.avatar_box {
  width: 100px;
  height: 100px;
  border: 1px solid #999;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 10px #999;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
}
.avatar_box img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #999;
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.loginbtn {
  width: 100%;
}
</style>